package com.sskj.mine.presenter;

import com.alibaba.android.arouter.launcher.ARouter;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.bean.enums.CodeTypeEnum;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.router.provider.SendSmsProvider;
import com.sskj.lib.util.CommonUtil;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.SettingFundPwdActivity;

public class SettingFundPwdPresenter extends BasePresenter<SettingFundPwdActivity> {
    // 获取验证码
    public void sendCode(String account) {
        SendSmsProvider sendSmsProvider = ARouter.getInstance().navigation(SendSmsProvider.class);
        sendSmsProvider.send(this, account, SPUtil.get(SPConfig.AREA_CODE, ""), CodeTypeEnum.STATUS_4, null, new SendSmsProvider.OnSend() {
            @Override
            public void onSuccess() {
                mView.onSendCodeSuccess();
            }

            @Override
            public void onFail() {
            }
        });

    }

    //设置资金密码
    public void setFundPwd(String code,String pwd) {
        String account = SPUtil.get(SPConfig.USER_ACCOUNT, "");
        String areaCode=null;
        if (account.contains("@")){
            areaCode=null;
        }else {
            areaCode=SPUtil.get(SPConfig.AREA_CODE,"").replace("+","");
        }
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SETFUNDPWD)
                .params("id", SPUtil.get(SPConfig.ID, ""))
                .params("code", code)
                .params("areaCode",areaCode)
                .params("account", SPUtil.get(SPConfig.USER_ACCOUNT, ""))
                .params("dealPswd", pwd,true)
                .execute(new JsonCallBack<HttpData>(this) {

                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());
                        mView.onSetSuccess();
                    }
                });
    }
}
